package utils;

import com.sun.org.apache.xerces.internal.xs.StringList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @Author 小白龙
 * @Date 2021-01-05
 * @Version 1.0
 */
public class StringUtils {

    /**
     * 校验是否为空
     *
     * @param str
     * @return
     */
    public static boolean isEmpty(Object str) {
        return str == null || "".equals(str);
    }

    /**
     * 将字符串列表转字符串
     *
     * @param stringList
     * @param separator
     * @return
     */
    public static String buildStr(List<String> stringList, String separator) {
        return Optional.ofNullable(stringList).orElse(new ArrayList<String>())
                .stream().collect(Collectors.joining(separator));
    }

    /**
     * 构建字符串
     *
     * @param strArr
     * @param separator
     * @return
     */
    public static String buildStr(String[] strArr, String separator) {
        return buildStr(Arrays.asList(strArr), separator);
    }
}
